package com.hxy.platform.admin.service.impl;

import com.hxy.platform.admin.dao.ProductMapper;
import com.hxy.platform.admin.pojo.Product;
import com.hxy.platform.admin.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ProductServiceImpl implements ProductService {
    @Autowired
    private ProductMapper productMapper;

    /**
     * 查询所有商品
     * @return
     */
    @Override
    public List<Product> getAll() {
        return productMapper.getAll();
    }

    /**
     * 添加商品
     * @param product
     * @return
     */
    @Override
    public int addProduct(Product product) {
        Product newProduct = new Product();
        newProduct.setTitle(product.getTitle());
        newProduct.setCilckNum(product.getCilckNum());
        newProduct.setIshot(product.getIshot());
        newProduct.setOldProce(product.getOldProce());
        newProduct.setNowPrice(product.getNowPrice());
        newProduct.setProductDesc(product.getProductDesc());
        newProduct.setQuantity(product.getQuantity());
        newProduct.setImgUrl(product.getImgUrl());
        newProduct.setStatus("在售");
        return productMapper.insertSelective(newProduct);
    }

    /**
     * 删除产品id
     * @param id
     * @return
     */
    @Override
    public int deleteProductById(Integer id) {
        return productMapper.deleteByPrimaryKey(id);
    }
}
